<?php
namespace app\channel\controller;
use think\Db;

class GameUpdate extends Base
{
    //CPS一级渠道和联运渠道可以访问
    public function _initialize(){
        parent::_initialize();
        /*
        $arr = [
            1000
            ,5070
            ,5118
            ,5027
            ,1082
            ,5005
            ,5112
            ,1085
            ,5203
            ,5102
            ,1085
            ,5119
            ,5072
            ,5120
            ,5087
            ,5107
            ,5013
            ,1164
            ,5007
            ,5063
            ,5078
            ,1769
            ,5024
            ,5064
            ,2128
            ,1271
            ,1451
            ,5052
            ,1950
            ,5073
            ,5040
            ,2182
            ,5016
            ,5081
            ,5068
        ];
        if(session('admin.cps_id')){
            if(!in_array(session('admin.cps_id'), $arr)){
                $this->error('访问错误');
            }
        }else if(session('admin.sdk_id')){
            if(!in_array(session('admin.sdk_id'), $arr)){
                $this->error('访问错误');
            }
        }*/
    }

    public function index(){
        if( request()->isAjax() ){
            $cmd1 = input('cmd1');
            $cmd2 = input('cmd2');
            $server = input('server');
            if($server==''){
                $this->layJson(1, '请选择区服');
            }

            if($cmd1=='' && $cmd2==''){
                $this->layJson(1, '请至少选择一个神兽');
            }

            $arr['server'] = $server;
            $arr['cmd'] = $cmd1 . ' ' . $cmd2;
            $arr['token'] = '1b6fb957004a46311c81b4aab8f6ab23';
            $arr['name'] = 'zl';
            $json1 = http('http://gmtool.miyuhaiwai.com/admin/cmd/verpmpet?name=zl', $arr, 'post');
            $json = json_decode($json1, true);
            if($json['status']==1){
                $this->layJson(0, '更新成功');
            }else{
                $this->layJson(1, '更新失败，请联系客服人员');
            }
        }else{
            $json = http('http://gmtool.miyuhaiwai.com/admin/cmd/verCmd?name=zl', [], 'post');
            $arr = json_decode($json, true);
            return view('', ['server'=>$arr['server'], 'cmd'=>$arr['cmd']]);
        }
    }
}
